package features.advance.client;

import lombok.extern.slf4j.Slf4j;

import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @author LIN
 * @date 2023-06-15 16:00
 */
@Slf4j
public class VocabularyHandler {

    public static void main(String[] args) {
        InputStream stream = VocabularyHandler.class.getResourceAsStream("/static/vocabulary");
        byte[] data = new byte[1024*1024];
        int r = -1;
        StringBuilder sb = new StringBuilder();
        try{
            while((r= stream.read(data))!=-1){
                sb.append(new String(data,0,r, StandardCharsets.UTF_8));
            }
        }catch(Exception e){
            log.debug(e.getMessage());
        }
        String x = sb.toString().replaceAll("[\t|\r|\n|,|.|>|<|(|)|…|;|:|?|{|}]+", "\t");
        System.out.println(x);
        Arrays.stream(x.split("\t")).flatMap(e->{
            Map<String,Integer> map = new HashMap<>(16);
            map.put(e,1);
            return map.entrySet().stream();
        }).reduce((sum, cur) -> cur);


    }


}
